package cz.bernhard.playground.persistance.test.helpers;
import org.hamcrest.BaseMatcher;
import org.hamcrest.Description;
import org.hamcrest.Matcher;

import cz.bernhard.playground.persistance.domain.Book;


public class DomainMatchers {

	static Matcher<Book> isEqual(Book book) {
		return new BookIsEqualMatcher(book);
	}
	
	static class BookIsEqualMatcher extends BaseMatcher<Book> {

		private Book book;

		public BookIsEqualMatcher(Book book) {
			this.book = book;
		}

		public boolean matches(Object object) {
			Book book2 = (Book) object;
			
			if (book.getTitle().equals(book2.getTitle())
					&& book.getAuthor().equals(book2.getAuthor())
					&& book.getPublisher().equals(book2.getPublisher())) {
				return true;
			}
			
			return false;
					
		}

		public void describeTo(Description description) {
			// TODO: 5.1.2011 mbernhard: add support author, publisher 
			description
				.appendText("title").appendValue(book.getTitle())
				.appendText("author").appendValue(book.getAuthor())
				.appendText("publisher").appendValue(book.getPublisher());			
		}
		
	}

}
